﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.18/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <form class="layui-form" action="">

        <div class="layui-form-item">
            <label class="layui-form-label">角色名称</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" name="rolesName" value="" id="rolesName" lay-verify="required" autocomplete="off" lay-reqtext="请输入角色名称" lay-affix="clear" class="layui-input demo-phone">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">角色编码</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" name="rolesCode" value="" id="rolesCode" lay-verify="required" autocomplete="off" lay-reqtext="请输入角色编码" lay-affix="clear" class="layui-input demo-phone">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">角色状态</label>
            <div class="layui-input-block">
                <input type="radio" name="isStatus" value="1" title="有效" checked>
                <input type="radio" name="isStatus" value="2" title="无效">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" id="component" class="layui-btn layui-btn-normal" lay-submit lay-filter="demo-val">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <script>
        layui.use(['form', 'laydate', 'util'], function () {
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var util = layui.util;

             // 表单取值
            layui.$('#component').on('click', function () {
                var data = form.val('demo-val-filter');
            });

            // 角色添加提交事件
            form.on('submit(demo-val)', function (data) {
                var field = data.field; // 获取表单字段值
                var username=localStorage.getItem('userName');
                console.log(username);
                field.createdOwner =username;
                field.createdTime = "" || new Date().toISOString();
                field.updateOwner = "" || null;
                field.updateTime = "" || new Date().toISOString();
                field.examineOwner = "" || null;
                field.examineTime = "" || new Date().toISOString();
                field.isDel = 1;
                console.log(field) //在控制台显示值
                // 此处可执行 Ajax 等操作
                $.ajax({
                    type: "post",
                    url: '@ViewBag.RBACWrite'+"/api/Roles/AddRoles",
                    data: JSON.stringify(field),
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        console.log(res)
                        // 处理响应，例如提示成功信息
                        layui.layer.msg(res.msg ,{ icon: 6, time: 1000 });
                    },
                    error: function (xhr, status, error) {
                        // 处理错误
                        layui.layer.msg('添加失败', { icon: 5, time: 1000 });
                    }
                })
                return false; // 阻止默认 form 跳转
            });

        });
    </script>
</body>

</html>

